# coding=utf-8
# 代码文件：chapter12/ch12.3.1.py
import tkinter as tk
from tkinter import messagebox

window = tk.Tk()

window.title('messagebox！')
#  设定窗口的大小(宽x高)
window.geometry('320x258')


def onClick1():
    # 调用showinfo函数
    messagebox.showinfo('信息', '打开文件ABC.txt!')


def onClick2():
    # 调用showerror函数
    messagebox.showerror('错误', '文件没有找到！')


def onClick3():
    # 调用showwarning函数
    messagebox.showwarning('警告', '忽略文件后缀名！')


def onClick4():
    # 调用askquestion函数
    ret = messagebox.askquestion('询问用户', '您想继续吗？')
    print(ret)


def onClick5():
    # 调用askyesnoaskokcancel函数
    ret = messagebox.askokcancel('询问用户', '您确认删除文件吗？')
    print(ret)


def onClick6():
    # 调用askyesno函数
    ret = messagebox.askyesno('询问用户', '您想继续吗？')
    print(ret)


def onClick7():
    # 调用askyesnocancel函数
    ret = messagebox.askyesnocancel('询问用户', '您想继续吗？')
    print(ret)


def onClick8():
    # 用askretrycancel函数
    ret = messagebox.askretrycancel('打开失败', '打开文件失败！您想继续尝试吗？')
    print(ret)


# 创建按钮对象
button1 = tk.Button(window, text='测试showinfo函数', command=onClick1)
button2 = tk.Button(window, text='测试showerror函数', command=onClick2)
button3 = tk.Button(window, text='测试showwarning函数', command=onClick3)
button4 = tk.Button(window, text='测试askquestion函数', command=onClick4)
button5 = tk.Button(window, text='测试askokcancel函数', command=onClick5)
button6 = tk.Button(window, text='测试askyesno函数', command=onClick6)
button7 = tk.Button(window, text='测试askyesnocancel函数', command=onClick7)
button8 = tk.Button(window, text='测试askretrycancel函数', command=onClick8)

button1.pack(fill=tk.BOTH)
button2.pack(fill=tk.BOTH)
button3.pack(fill=tk.BOTH)
button4.pack(fill=tk.BOTH)
button5.pack(fill=tk.BOTH)
button6.pack(fill=tk.BOTH)
button7.pack(fill=tk.BOTH)
button8.pack(fill=tk.BOTH)

# 将窗口对象加入到主事件循环
window.mainloop()
